package com.swiftops.common.core;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ModelAttribute;

//@RestControllerAdvice
public class ApiControllerAdvice {

    //@ModelAttribute 这个注解用于将方法的返回值添加到模型中。在这个情况下，它被用于增强 ResponseEntity<T> 类型的返回值。
    @ModelAttribute
    public <T> ResponseEntity<ApiResult<T>> apiResult(ResponseEntity<T> response) {
        ApiResult<T> apiResult = new ApiResult<>();
        apiResult.setCode(response.getStatusCodeValue());
        apiResult.setData(response.getBody());
        apiResult.setMessage("success");
        return ResponseEntity.ok(apiResult);
    }
}
